package com.example.day04;

public class Test {
    public static void main(String[] args) {
        //向上造型
//        Master master = new Master();
//        Dog dog = new Dog("小黑",2,"黑");
//        Chick chick = new Chick("小花",8,"花");
//        Fish fish = new Fish("小红",4,"红");
//        master.feed(dog);
//        master.feed(fish);
//        master.feed(chick);
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑",2,"黑");
        animals[1] = new Dog("小白",5,"白");
        animals[2] = new Chick("小花",8,"花");
        animals[3] = new Fish("小金",6,"金");
        animals[4] = new Fish("小红",4,"红");
        for (int i = 0; i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            if(animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
                dog.swim();
            }
            if(animals[i] instanceof Fish){
                Fish fish = (Fish) animals[i];
                fish.swim();
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
        }
    }
}
